from typing import List, Optional

from pydantic import BaseModel, Field, model_validator

from forward.api.admin.schemas.lucky.activity_code_no import (
    ActivityCodeNoDetailOutSchema,
)
from forward.extend.pydantic.base import BaseSchema
from forward.model.schemas.lucky.activity import (
    ActivityCodeNoSchema,
    ActivityPrizeOutSchema,
    ActivitySchema,
)
from forward.utils.tools import ToolsUtil


class ActivityPrizeSchema(BaseSchema):
    prize_id: int | None = None
    activity_id: int | None = None
    num: int | None = None
    prize_level_id: str | None = None
    probability: float | None = None
    prize_index: int | None = Field(
        None, description="奖品索引==一等奖 这样的序号，谢谢惠顾是0"
    )


class ActivityAddInSchema(ActivitySchema):
    activity_prize_list: List[ActivityPrizeSchema]
    activity_code_no_list: List[ActivityCodeNoSchema]
    pass


class ActivityListOutSchema(ActivitySchema):
    id: int
    merchant_name: str | None = Field(None, description="商户名称")
    type_str: str | None = Field(None, description="活动类型")
    qrcode_img_url: str | None = Field(None, description="活动二维码图片地址")
    qrcode_redirect_url: str | None = Field(None, description="app跳转抽奖地址")
    residue_count: int | None = None
    # prizes: List[ActivityPrizeSchema] | None = None


class ActivityDetailInfoSchema(ActivitySchema):
    id: int
    merchant_name: str | None = Field(None, description="商户名称")
    type_text: str | None = Field(None, description="活动类型")
    qrcode_img_url: str | None = Field(None, description="活动二维码图片地址")
    qrcode_redirect_url: str | None = Field(None, description="app跳转抽奖地址")
    residue_count: int | None = None


class ActivityDetailOutSchema(ActivitySchema):
    id: int
    merchant_name: str | None = Field(None, description="商户名称")
    type_text: str | None = Field(None, description="活动类型")
    qrcode_img_url: str | None = Field(None, description="活动二维码图片地址")
    qrcode_redirect_url: str | None = Field(None, description="app跳转抽奖地址")
    guaguale_qrcode_url: str | None = Field(None, description="刮刮乐二维码地址")
    guaguale_url:  str | None = Field(None, description="刮刮乐地址")
    residue_count: int | None = None
    activity_prize_list: list[ActivityPrizeOutSchema]
    activity_code_no_list: list[ActivityCodeNoDetailOutSchema]


class ActivityEditInSchema(ActivitySchema):
    id: int
    # activity_prize_list: List[ActivityPrizeSchema]


class ActivityListInSchema(BaseSchema):
    merchant_id: int | None = None
    salesman_id: int | None = None
    status: int | None = None
    page_no: int = 1
    page_size: int = 20
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class ActivityDetailInSchema(BaseModel):
    id: int


class ActivityDeleteInSchema(BaseModel):
    id: int


class GenerateInSchema(BaseModel):
    count: int


class ActivityStatusInSchema(BaseModel):
    id: int
    status: int


class ActivityCancleInSchema(BaseSchema):
    activity_id: int
